package com.taxigang.client;

import com.taxigang.client.uibinder.TaxiGangPresenter.CreateJoinMode;
import com.taxigang.shared.LoginInfo;
import com.taxigang.shared.RouteInfo;
import com.taxigang.shared.TaxiGangInfo;
import com.taxigang.shared.TaxiGanguserInfo;

public class Session {
	public enum UserAgent {PC,FB_WEBKIT,PC_WEBKIT,IPHONE,ANDROID,FB, IPAD, MAC, FB_PAGE}
	public enum Property {PRESET_ROUTE}

	
	private TaxiGangInfo[] taxigangInfoList;
	private TaxiGangInfo[] myTaxigangInfoList;
	private TaxiGangInfo searchtaxigangInfo;
	private TaxiGangInfo jointaxigangInfo;
	private LoginInfo loginInfo = new LoginInfo();
	private TaxiGanguserInfo taxigangUserInfo;
	private UserAgent userAgent;
	private int currentSuggestion;
	private int currentMyTaxiGang;
	private boolean mapIsShown;
	private boolean adminMode;
	private String locale;
	private String country;
	private boolean isIncubator;
	private boolean isLocalHost;
//	private TaxiCompanyInfo[] taxiCompanyList;
	private String startCity;
	private RouteInfo route;
	private String ref;
	private String cron;
	private String wishRouteCancel;
	private String testAgent;
	private TaxigangMode mode;
	
	private String presetRoute;
	private CreateJoinMode createJoinMode;
	private TaxiGanguserInfo currentShowAwardsUser;
	private static Session instance = new Session();
	public static Session getInstance(){
		return instance;		
	}
	private Session(){

	}
	public void setTaxiGangUserInfo(TaxiGanguserInfo taxiGanguserInfo) {
		this.taxigangUserInfo = taxiGanguserInfo;
	}

	public TaxiGanguserInfo getTaxiGangUserInfo() {
		return taxigangUserInfo;
	}

	public UserAgent getUserAgent() {
		return userAgent;
	}

	public void  setUserAgent(UserAgent userAgent) {
		this.userAgent = userAgent;
	}


	public TaxiGangInfo getSearchTaxiGangInfo(){
		if (searchtaxigangInfo==null){
			searchtaxigangInfo = new TaxiGangInfo();
		}
		return searchtaxigangInfo;
	}

	public TaxiGangInfo getJoinTaxiGangInfo(){
		return jointaxigangInfo;
	}

	public  void setJoinTaxiGangInfo(TaxiGangInfo taxigangInfo){
		this.jointaxigangInfo = taxigangInfo;
	}

	public  TaxiGangInfo getTaxiGangInfo(int i){
		TaxiGangInfo taxiGangInfo = null;
		if (i >= 0 && i < taxigangInfoList.length){
			taxiGangInfo = taxigangInfoList[i];
		}
		return taxiGangInfo;
	}

	public  void setTaxiGangSearchResultList(TaxiGangInfo[] taxigangInfoList){
		this.taxigangInfoList = taxigangInfoList;
	}

	public  TaxiGangInfo[] getTaxiGangSearchResultList( ){
		return taxigangInfoList;
	}

	public  void setMyTaxiGangInfoList(TaxiGangInfo[] taxigangInfoList){
		currentMyTaxiGang = 0;
		this.myTaxigangInfoList = taxigangInfoList;
	}

	public  TaxiGangInfo[] getMyTaxiGangInfoList( ){
		return myTaxigangInfoList;
	}


	public LoginInfo getLoginInfo(){
		return loginInfo;
	}
	public  void setLoginInfo(LoginInfo info){
		loginInfo = info;
	}

	public int getCurrentSuggestionIndex(){
		return currentSuggestion;
	}
	public void setCurrentSuggestionIndex(int currentSuggestion){
		this.currentSuggestion = currentSuggestion;
	}

	public TaxiGangInfo[] getMyTaxiGangList(){
		return myTaxigangInfoList;
	}

	public int getCurrentMyTaxiGangIndex(){
		return currentMyTaxiGang;
	}
	public void incCurrentMyTaxiGangIndex(){
		if(myTaxigangInfoList.length-1 > currentMyTaxiGang){
			currentMyTaxiGang++;
		}
	}
	public void decCurrentMyTaxiGangIndex(){
		if (currentMyTaxiGang > 0){
			currentMyTaxiGang--;
		}
	}

	public void resetCurrentMyTaxiGangIndex(){
		currentMyTaxiGang=0;
	}

	public void resetCurrentSuggestionIndex(){
		currentSuggestion=0;
	}
	public TaxiGanguserInfo getCurrentShowAwardsUser(){
		return currentShowAwardsUser;
	}
	public void setCurrentShowAwardsUser(TaxiGanguserInfo user){
		this.currentShowAwardsUser = user;
	}


	public TaxiGangInfo getCurrentMyTaxiGang(){
		TaxiGangInfo taxiGangInfo = null;
		if (myTaxigangInfoList != null){
			if (currentMyTaxiGang >=0 && currentMyTaxiGang < myTaxigangInfoList.length  ){
				taxiGangInfo = myTaxigangInfoList[currentMyTaxiGang];
			}
		}
		return taxiGangInfo;
	}


	//	public TaxiGangInfo getNextMyTaxiGang(){
	//		TaxiGangInfo taxiGangInfo = null;
	//		if (currentMyTaxiGang >=0 && currentMyTaxiGang < myTaxigangInfoList.length -1 ){
	//			taxiGangInfo = myTaxigangInfoList[currentMyTaxiGang+1];
	//			currentMyTaxiGang++;
	//		}
	//		return taxiGangInfo;
	//	}
	//	public TaxiGangInfo getPreviousMyTaxiGang(){
	//		TaxiGangInfo taxiGangInfo = null;
	//		if (currentMyTaxiGang >=1 && currentMyTaxiGang < myTaxigangInfoList.length  ){
	//			taxiGangInfo = myTaxigangInfoList[currentMyTaxiGang-1];
	//			currentMyTaxiGang--;
	//		}
	//		return taxiGangInfo;
	//	}

	public  void setCurrentMyTaxiGang(TaxiGangInfo taxiganginfo){
		int index = 0;
		for (TaxiGangInfo tgi : myTaxigangInfoList){
			if (tgi.getId() == taxiganginfo.getId()){
				currentMyTaxiGang = index;
				break;
			}
			index++;
		}
	}

	public boolean getMapIsShown(){
		return mapIsShown;
	}
	public void setMapIsShown(boolean mapIsShown){
		this.mapIsShown=mapIsShown;
	}

	public String getLocale(){
		if (locale==null){
			locale="en";
		}
		return locale;
	}
	public void setLocale(String locale,String country){
		this.locale=locale;
		this.country=country;
		loginInfo.setLocale(locale,country);
	}

	public boolean getAdminMode(){
		return adminMode;
	}
	public void setAdminMode(boolean adminMode){
		this.adminMode=adminMode;
	}
	public void setIsIncubator(boolean contains) {
		isIncubator = contains;

	}
	public boolean getIsIncubator() {
		return isIncubator;

	}

	public void setIsLocalhost(boolean isLocalHost) {
		this.isLocalHost = isLocalHost;

	}
	public boolean getIsLocalhost() {
		return isLocalHost;

	}
//	public TaxiCompanyInfo[] getTaxiCompanyList() {
//		return taxiCompanyList;
//	}
//	public void setTaxiCompanyList(TaxiCompanyInfo[] taxiCompanyList) {
//		//		TaxiCompanyInfo[] list = new TaxiCompanyInfo[20];
//		//		for (int i = 0; i<list.length; i++){
//		//			list[i]= new TaxiCompanyInfo();
//		//			list[i].setTelAreaCode(18041);
//		//			list[i].setTelNo(5555);
//		//			list[i].setName("Black&White------"+i);
//		//		}
//		this.taxiCompanyList=taxiCompanyList;
//	}
	public void setPostalCode(String postalCode) {
		getSearchTaxiGangInfo().setPostalCode(postalCode);		
	}

	public String getPostalCode() {
		return getSearchTaxiGangInfo().getPostalCode();		
	}
	public boolean getLocalHost() {
		return isLocalHost;
	}
	public void setLocalHost(boolean isLocalHost) {
		this.isLocalHost=isLocalHost;
	}
	public void setStartCity(String startCity) {
		this.startCity = startCity;		
	}
	public String getStartCity() {
		return startCity;		
	}
	public String getPresetRoute() {		
		return presetRoute;
	}
	public void setPresetRoute(String value) {		
		presetRoute = value;
	}
	public boolean getIsUserAgentMobile() {
		// TODO Auto-generated method stub
		return userAgent==UserAgent.ANDROID || userAgent==UserAgent.IPHONE;
	}
	public void incCurrentSuggestionIndex() {
		currentSuggestion++;
		
	}
	public void decCurrentSuggestionIndex() {
		currentSuggestion--;
		
	}
	public void setCreateJoin(CreateJoinMode createJoinMode) {
		this.createJoinMode = createJoinMode;
		
	}
	public CreateJoinMode getCreateJoin() {
		return createJoinMode;
	}
	public void setWishRouteCancel(String wishRouteCancel) {
		this.wishRouteCancel = wishRouteCancel;
	}
	public String getWishRouteCancel() {
		return wishRouteCancel;
	}
	public void setTestAgent(String agent) {
		this.testAgent = agent;	
	}
	public String getTestAgent() {
		return testAgent;	
	}
	public void setRoute(RouteInfo route) {
		this.route = route;		
	}
	public RouteInfo getRoute() {
		return route;		
	}
	public void setRef(String ref) {
		this.ref = ref;		
	}
	public String getRef() {
		return ref;		
	}
	public void setMode(TaxigangMode mode) {
		this.mode = mode;		
	}
	public TaxigangMode getMode() {
		return mode;		
	}
	public void setCron(String cron) {
		this.cron=cron;
	}
	public String getCron() {
		return cron;
	}

}
